import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {getAllTenantList} from "@/views/system/user/user.api";
import {queryList as getCarrierList} from "@/views/wms/carrier/WmsCarrier.api";
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '收货单',
    align:"center",
    dataIndex: 'harvestNo'
   },
   {
    title: '单据状态',
    align:"center",
    dataIndex: 'harvestStatus_dictText'
   },
   {
    title: '检验状态',
    align:"center",
    dataIndex: 'checkStatus_dictText'
   },
   {
    title: '承运商',
    align:"center",
    dataIndex: 'carrierId'
   },
   {
    title: '司机',
    align:"center",
    dataIndex: 'driver'
   },
   {
    title: '车牌号',
    align:"center",
    dataIndex: 'plateNumber'
   },
   {
    title: '联系方式',
    align:"center",
    dataIndex: 'phone'
   },
   {
    title: '收货类型',
    align:"center",
    dataIndex: 'harvestType_dictText'
   },
   {
    title: '生产车间',
    align:"center",
    dataIndex: 'workshop'
   },
   {
    title: '生产小组',
    align:"center",
    dataIndex: 'productionTeam'
   },
   {
    title: '生产责任人',
    align:"center",
    dataIndex: 'responsiblePerson'
   },
   {
    title: '退货来源',
    align:"center",
    dataIndex: 'returnSource'
   },
   {
    title: '退货原因',
    align:"center",
    dataIndex: 'returnReason'
   },
   {
    title: '是否运输',
    align:"center",
    dataIndex: 'isTransport'
   },
   {
    title: '创建人',
    align:"center",
    dataIndex: 'createBy'
   },
   {
    title: '创建时间',
    align:"center",
    sorter: true,
    dataIndex: 'createTime'
   },
   {
    title: '更新人',
    align:"center",
    dataIndex: 'updateBy'
   },
   {
    title: '更新时间',
    align:"center",
    sorter: true,
    dataIndex: 'updateTime'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "收货单",
      field: 'harvestNo',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "单据状态",
      field: 'harvestStatus',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "检验状态",
      field: 'checkStatus',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "承运商",
      field: 'carrierId',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "司机",
      field: 'driver',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "车牌号",
      field: 'plateNumber',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "联系方式",
      field: 'phone',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "收货类型",
      field: 'harvestType',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "生产车间",
      field: 'workshop',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "生产小组",
      field: 'productionTeam',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "生产责任人",
      field: 'responsiblePerson',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "退货来源",
      field: 'returnSource',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "退货原因",
      field: 'returnReason',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "是否运输",
      field: 'isTransport',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "创建人",
      field: 'createBy',
      component: 'Input',
      //colProps: {span: 6},
 	},
     {
      label: "创建时间",
      field: "createTime",
      component: 'RangePicker',
      componentProps: {
          valueType: 'Date',
          showTime:true
      },
      //colProps: {span: 6},
	},
	{
      label: "更新人",
      field: 'updateBy',
      component: 'Input',
      //colProps: {span: 6},
 	},
     {
      label: "更新时间",
      field: "updateTime",
      component: 'RangePicker',
      componentProps: {
          valueType: 'Date',
          showTime:true
      },
      //colProps: {span: 6},
	},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '承运商',
    field: 'carrierId',
    component: 'ApiSelect',
    componentProps: {
      mode: 'multiple',
      api: getCarrierList,
      numberToString: true,
      labelField: 'carrierName',
      valueField: 'carrierId',
      immediate: false,
    },
  },
  {
    label: '司机',
    field: 'driver',
    component: 'JSelectUser',
    componentProps: {
      //取值字段配置,一般为主键字段
      rowKey: 'username',
      //显示字段配置
      labelKey: 'realname',
      //是否显示选择按钮
      showButton: false,
      //用户标题
      modalTitle: '用户',
    },
  },
  {
    label: '车牌号',
    field: 'plateNumber',
    component: 'Input',
  },
  {
    label: '联系方式',
    field: 'phone',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: false},
                 { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
          ];
     },
  },
  {
    label: '收货类型',
    field: 'harvestType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'havest_type',
      placeholder: '请选择收货类型',
      stringToNumber: true,
    },
  },
  {
    label: '生产车间',
    field: 'workshop',
    component: 'Input',
  },
  {
    label: '生产小组',
    field: 'productionTeam',
    component: 'Input',
  },
  {
    label: '生产责任人',
    field: 'responsiblePerson',
    component: 'Input',
  },
  {
    label: '退货来源',
    field: 'returnSource',
    component: 'Input',
  },
  {
    label: '退货原因',
    field: 'returnReason',
    component: 'Input',
  },
  {
    label: '是否运输',
    field: 'isTransport',
    component: 'RadioGroup',
    componentProps: {
      //options里面由一个一个的radio组成,支持disabled
      options: [
        { label: '是', value: 0 },
        { label: '否', value: 1 },
      ],
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  harvestNo: {title: '收货单',order: 0,view: 'text', type: 'string',},
  harvestStatus: {title: '单据状态',order: 1,view: 'number', type: 'number',},
  checkStatus: {title: '检验状态',order: 2,view: 'number', type: 'number',},
  carrierId: {title: '承运商',order: 3,view: 'number', type: 'number',},
  driver: {title: '司机',order: 4,view: 'text', type: 'string',},
  plateNumber: {title: '车牌号',order: 5,view: 'text', type: 'string',},
  phone: {title: '联系方式',order: 6,view: 'text', type: 'string',},
  harvestType: {title: '收货类型',order: 7,view: 'number', type: 'number',},
  workshop: {title: '生产车间',order: 8,view: 'text', type: 'string',},
  productionTeam: {title: '生产小组',order: 9,view: 'text', type: 'string',},
  responsiblePerson: {title: '生产责任人',order: 10,view: 'text', type: 'string',},
  returnSource: {title: '退货来源',order: 11,view: 'text', type: 'string',},
  returnReason: {title: '退货原因',order: 12,view: 'text', type: 'string',},
  isTransport: {title: '是否运输',order: 13,view: 'number', type: 'number',},
  createBy: {title: '创建人',order: 14,view: 'text', type: 'string',},
  createTime: {title: '创建时间',order: 15,view: 'datetime', type: 'string',},
  updateBy: {title: '更新人',order: 16,view: 'text', type: 'string',},
  updateTime: {title: '更新时间',order: 17,view: 'datetime', type: 'string',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
